/**
* Created by Jimmy on 2018/12/11.
*/
<template>
  <div class="people-managment ">
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/panel/project/setting' }">其他设置</el-breadcrumb-item>
    </el-breadcrumb>
    <el-form v-model="form" ref="form">
      <el-form-item label="自主上报比例：">
        <el-input placeholder="" v-model="form.Upcoe" size="small" disabled></el-input>
        <el-button type="primary" @click="dialogVisible = true" size="small">修改</el-button>
      </el-form-item>
    </el-form>
    <el-dialog
      title="自主上报比例"
      :visible.sync="dialogVisible"
      width="50%">
      <el-form  ref="form" v-model="form">
        <el-form-item>
            <el-input placeholder="请输入自主上报比例" v-model="form.UpcoeX" size="small"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="save">保 存</el-button>
        </span>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    data(){
      return {
        dialogVisible:false,
        form:{
          Upcoe:"50%",
          UpcoeX:""
        }
      };
    },
    created: function(){
      let user = JSON.parse(window.localStorage.getItem('access-user'))
      this.token = user.Token
      this.getUpCoe()
    },
    methods: {
      getUpCoe(){
        this.$http.post(this.domain + '/setting/get',
          {
            token:this.token,
          }
        ).then((response) => {
          if (response.data.Success) {
            this.form.Upcoe = (response.data.Data.SetValue * 100).toFixed(2) + "%"
          } else {
            this.$message.error(response.data.Msg)
          }
        }).catch((response) => {
          this.$message.error(response.data)
        })
      },
      save(){
        let arg = parseFloat(this.form.UpcoeX)
        if(!isNaN(arg) && arg > 0 && arg <=1 ){
          this.$http.post(this.domain + '/setting/upcoe/set',
            {
              token:this.token,
              setvalue: arg
            }
          ).then((response) => {
            if (response.data.Success) {
              this.$message.success(response.data.Msg)
              this.getUpCoe()
              this.dialogVisible = false
            } else {
              this.$message.error(response.data.Msg)
              this.dialogVisible = false
            }
          }).catch((response) => {
            this.$message.error(response)
            this.dialogVisible = false
          })
        }
      }
    }
  }
</script>
<style>
  .people-managment>h4{
    line-height: 36px;
    height: 36px;
  }
  .edit-p-dialog .el-dialog__body{
    padding-right: 60px;
  }
  .edit-p-dialog  .el-dialog{
    width: 450px;
  }
  .locked{
    color: red;
    font-size: 12px;
  }
  .el-form-item__label{
    font-weight: 700;
  }
  .show-search{
    height: 250px;
    overflow: scroll;
  }
</style>

